package com.chancingpack.controller;

import com.alibaba.fastjson.JSONObject;
import com.chancingpack.service.WxForselectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/7/31.
 */
@Controller
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private WxForselectService wxForselectService;

    //我的订单页面
    @RequestMapping("/orderList")
    public ModelAndView orderList(HttpServletRequest request){
        ModelAndView view=new ModelAndView("/order/orderList");
        String consiId=(String)request.getSession().getAttribute("custId");
        List<Map<String, Object>> orderMap=wxForselectService.selectMapByCustId(consiId);
        for (int i=0;i<orderMap.size();i++) {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            String signup_time = formatter.format(orderMap.get(i).get("signup_time"));
            orderMap.get(i).put("signup_time",signup_time);
        }
        view.addObject("orderMap", JSONObject.toJSONString(orderMap));
        return view;
    }

    //查看物流页面
    @RequestMapping("/logisticsList")
    public ModelAndView logisticsList(Integer detail_id,HttpServletRequest request,String archId){
        ModelAndView view=new ModelAndView("/order/logisticsList");
        Map<String, Object> logisticsListA=wxForselectService.selectStateA(detail_id);
        /*//查找图片id
        String archId=wxForselectService.selectMapByDetailId(detail_id);*/
        view.addObject("logisticsListA", logisticsListA);
        //获取相应产品压缩图片Url,通过archId将它放入map中
        String compressUrl = request.getContextPath() + "/resources/upload/compress/" + archId+".jpg";
        view.addObject("compressUrl", compressUrl);

        Map<String, Object> logisticsListB=wxForselectService.selectStateB(detail_id);
        view.addObject("logisticsListB", logisticsListB);

        List<Map<String,Object>> logisticsListMapC=wxForselectService.selectStateC(detail_id);
        view.addObject("logisticsListMapC", logisticsListMapC);

        List<Map<String,Object>> logisticsListMapD=wxForselectService.selectStateD(detail_id);
        view.addObject("logisticsListMapD", logisticsListMapD);
        return view;
    }

}
